# test03_time.py   09~12
# 1. 09 12 转换成结构化时间
# 2. 按行读取文件(while True + readline/readlines)
# 3. 获取日志中每一行表示时间的字符串,并转换为结构化时间
# 4. 判断是否在9~12范围内
import time
t9=time.strptime("2030-01-02 09:00:00","%Y-%m-%d %H:%M:%S")
t12=time.strptime("2030-01-02 12:00:00","%Y-%m-%d %H:%M:%S")
fr = open("/opt/myweb.log", mode="r")
for item in fr.readlines():  # item: 每一行日志
    str_time = item[:19]  # 每一行表示时间的字符串
    t = time.strptime(str_time, "%Y-%m-%d %H:%M:%S")
    if t9 <= t <= t12:
        print(item, end="")
fr.close()


# file: /opt/myweb.log
# 2030-01-02 08:01:43 aaaaaaaaaaaaaaaaa
# 2030-01-02 08:34:23 bbbbbbbbbbbbbbbbbbbb
# 2030-01-02 09:23:12 ccccccccccccccccccccc
# 2030-01-02 10:56:13 ddddddddddddddddddddddddddd
# 2030-01-02 11:38:19 eeeeeeeeeeeeeeee
# 2030-01-02 12:02:28 ffffffffffffffff